<template>
  <span class="text-right" v-if="showOptMerge">
    <el-button size="mini" type="default" @click="mergeIn"
      ><span :data-clipboard-text="waybillNo" style="color:#468e70">
        合并开票</span
      ></el-button
    >
  </span>
</template>

<script>
import axios from "axios";
import * as constant from "@/store/yg/common/constant";
import { ajax, actionPermission } from "@/store/yg/common/utils";
import { m } from "@/store/yg/common/local";
export default {
  data() {
    return {
      showOptMerge: false,
      waybillNo: "",
      arr: []
    };
  },

  methods: {
    m(val) {
      return m(val);
    },
    mergeIn() {
      this.arr = [];
      var ids = [];
      this.arr = this.$store.state.main.selectedData;
      if (this.arr.length > 0) {
        for (let i of this.arr) {
          ids.push(i.id);
        }
        var param = {};
        param.ids = ids;
        console.log(ids);
        ajax("applyMergeForInvoice", param).then(
          res => {
            if (res.success) {
              window.open(
                `#/blank/customer__billinvoice__main?ids=${ids}&customerId=${res.customerId}`
              );
            } else {
              this.$message.error(m(res.message));
            }
          },
          error => {
            console.log(error);
          }
        );
      } else {
        return this.$message.error("请先勾选账单再合并");
      }
    },
    loadCurrrntUser() {
      var param = {};
      ajax("authority", param).then(
        res => {
          console.log(res);
          if (res && res === 1) {
            this.showOptMerge = true;
          }
        },
        error => {
          console.log(error);
        }
      );
    }
  },
  mounted() {
    this.loadCurrrntUser();
  }
};
</script>

<style></style>
